<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <link rel="stylesheet" href="../../../layui/css/layui.css" media="all">
    <script src="../../../js/jquery/3.5.1/jquery.js"></script>
    <script src="../../../layui/layui.js" charset="utf-8"></script>
    <script src="../../../js/config.js"></script>
    <script src="../../../js/public.js"></script>
    <script src="../../../js/function.js"></script>
    <link rel="stylesheet" href="../../../css/public.css">
    <link rel="stylesheet" href="../../../css/patient/qss.css?v=3">
    <style>
        .qss-item {
            margin: 15px 0px
        }

        .date {
            width: 80px!important;
            text-align: center
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="tab-title">
            <ul class="tab-title-tab">
                <li>
                    <a href="../V1_1/patient_info.html">
                        <p>基本信息</p>
                        <p class="complete_basic">0%</p>
                    </a>
                </li>
                <li class="tab-curr">
                    <a>
                        <p>病历采集</p>
                        <p class="complete_qss">0%</p>
                    </a>
                </li>
                <li>
                    <a href="./qss7.html">
                        <p>检查信息</p>
                        <p style="display: none;">0%</p>
                    </a>
                </li>
                <div class="clear"></div>
            </ul>
        </div>
        <div class="qss-container">
            <div class="qss-box">
                <div class="qss-box-title">
                    <p>个人疾病史</p>
                </div>
                <form class="layui-form qss-form">
                    <div class="qss-item">
                        <div class="qss-item-title">
                            <p>1、诊断时存在垂体功能减退：</p>
                        </div>
                        <div class="qss-form-item layui-form-item switch-line">
                            <div class="layui-form-label">a.肾上腺皮质功能减退</div>
                            <div class="layui-input-inline qss-input-swipch">
                                <div class="switch3" data-qid="111" id="switch-111" title="是|否" option="0|1|2" value=""></div>
                            </div>
                        </div>
                        <div class="qss-form-item layui-form-item switch-line">
                            <div class="layui-form-label">b.甲状腺功能减退</div>
                            <div class="layui-input-inline qss-input-swipch">
                                <div class="switch3" data-qid="112" id="switch-112" title="是|否" option="0|1|2" value=""></div>
                            </div>
                        </div>
                        <div class="qss-form-item layui-form-item switch-line">
                            <div class="layui-form-label">c.性腺功能减退</div>
                            <div class="layui-input-inline qss-input-swipch">
                                <div class="switch3" data-qid="113" id="switch-113" title="是|否" option="0|1|2" value=""></div>
                            </div>
                        </div>
                        <div class="qss-form-item layui-form-item switch-line">
                            <div class="layui-form-label">d.生长激素缺乏</div>
                            <div class="layui-input-inline qss-input-swipch">
                                <div class="switch3" data-qid="114" id="switch-114" title="是|否" option="0|1|2" value=""></div>
                            </div>
                        </div>
                    </div>
                    <div class="qss-item">
                        <div class="qss-item-title">
                            <p>2、垂体后叶功能检测：</p>
                        </div>
                        <div class="qss-form-item layui-form-item switch-line">
                            <div class="layui-form-label">诊断时存在垂体后叶功能减退</div>
                            <div class="layui-input-inline qss-input-swipch">
                                <div class="switch3" data-qid="115" id="switch-115" title="是|否" option="0|1|2" value=""></div>
                            </div>
                        </div>
                    </div>
                    <div class="qss-item">
                        <div class="qss-item-title">
                            <p>3、发现或诊断患者有垂体疾病时间：</p>
                        </div>
                        <div class="qss-form-item layui-form-item">
                            <div class="layui-form-label">a.诊断患者有垂体疾病时间</div>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="116" lay-verify="date_116" lay-verType="tips" autocomplete="off" readonly="readonly" id="faxian-date">
                            </div>
                        </div>
                        <div class="qss-form-item layui-form-item">
                            <div class="layui-form-label">b.首诊科室：</div>
                            <div class="qss-form-item-radio layui-form-item">
                                <input type="radio" title="内分泌科" name="117" class="cv-11701" value="11701" lay-filter="radio117">
                                <input type="radio" title="神经外科" name="117" class="cv-11702" value="11702" lay-filter="radio117">
                                <input type="radio" title="放射治疗科" name="117" class="cv-11703" value="11703" lay-filter="radio117">
                                <input type="radio" title="神经内科" name="117" class="cv-11704" value="11704" lay-filter="radio117">
                                <input type="radio" title="妇产科" name="117" class="cv-11705" value="11705" lay-filter="radio117">
                                <input type="radio" title="眼科" name="117" class="cv-11706" value="11706" lay-filter="radio117">
                                <input type="radio" title="口腔科" name="117" class="cv-11707" value="11707" lay-filter="radio117">
                                <input type="radio" title="呼吸科" name="117" class="cv-11708" value="11708" lay-filter="radio117">
                            </div>
                        </div>
                    </div>
                    <!--//4---------------------->
                    <div class="qss-item">
                        <div class="qss-item-title">
                            <p>4、发现垂体疾病原因（首诊症状）：</p>
                        </div>
                        <div class="qss-form-item layui-form-item switch-line">
                            <div class="layui-form-label">是否体检或意外发现</div>
                            <div class="layui-input-inline qss-input-swipch">
                                <div class="switch3-2" data-qid="118" id="switch-118" title="是|否" option="0|1|2" value=""></div>
                            </div>
                        </div>
                        <div class="qss-form-item layui-form-item switch-line">
                            <div class="layui-form-label">是否存在肿瘤压迫临床症状</div>
                            <div class="layui-input-inline qss-input-swipch">
                                <div class="switch3-2" data-qid="119" id="switch-119" title="是|否" option="0|1|2" value=""></div>
                            </div>
                            <div class="qss-form-item-checkbox layui-form-item" id="opn-119" style="display: none;">
                                <input type="checkbox" lay-skin="primary" title="头痛" name="120" class="cv-12001" value="12001" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="头晕" name="120" class="cv-12002" value="12002" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="乏力" name="120" class="cv-12003" value="12003" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="视力下降" name="120" class="cv-12004" value="12004" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="视野缺损" name="120" class="cv-12005" value="12005" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="性功能减退/月经紊乱" name="120" class="cv-12006" value="12006" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="其他" name="120" class="cv-12007" value="12007" lay-filter="check1">
                                <input type="text" style="width:120px;" class="layui-input checkbox-check-input cv-12007001" lay-verify="other_text" lay-verType="tips" autocomplete="off" disabled="disabled" data-qid="12007001">
                                <!--<input type="text" class="layui-input radio-check-input">-->
                            </div>
                        </div>
                        <div class="qss-form-item layui-form-item switch-line">
                            <div class="layui-form-label">是否存在激素分泌亢进表现</div>
                            <div class="layui-input-inline qss-input-swipch">
                                <div class="switch3-2" data-qid="121" id="switch-121" title="是|否" option="0|1|2" value=""></div>
                            </div>
                            <div class="qss-form-item-checkbox layui-form-item" id="opn-121" style="display:none">
                                <input type="checkbox" lay-skin="primary" title="月经稀少或闭经" name="122" class="cv-12201" value="12201" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="不育" name="122" class="cv-12202" value="12202" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="溢乳" name="122" class="cv-12203" value="12203" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="女性多毛" name="122" class="cv-12204" value="12204" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="性欲减退或阳痿" name="122" class="cv-12205" value="12205" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="体重增加" name="1" class="cv-12206" value="12206" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="甲状腺功能亢进症" name="1" class="cv-12207" value="12207" lay-filter="check1">
                            </div>
                        </div>
                        <div class="qss-form-item layui-form-item switch-line">
                            <div class="layui-form-label">是否存在垂体功能低下表现</div>
                            <div class="layui-input-inline qss-input-swipch">
                                <div class="switch3-2" data-qid="123" id="switch-123" title="是|否" option="0|1|2" value=""></div>
                            </div>
                            <div class="qss-form-item-checkbox layui-form-item" id="opn-123" style="display:none">
                                <input type="checkbox" lay-skin="primary" title="乏力" name="124" class="cv-12401" value="12401" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="纳差" name="124" class="cv-12402" value="12402" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="怕冷" name="124" class="cv-12403" value="12403" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="浮肿" name="124" class="cv-12404" value="12404" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="多饮与多尿" name="124" class="cv-12405" value="12405" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="低血压" name="124" class="cv-12406" value="12406" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="月经稀少或闭经" name="124" class="cv-12407" value="12407" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="性欲减退或阳痿" name="124" class="cv-12408" value="12408" lay-filter="check1">
                                <!--v1.1-->
                                <input type="checkbox" lay-skin="primary" title="生长发育迟缓" name="124" class="cv-12409" value="12409" lay-filter="check1">
                            </div>
                        </div>
                        <div class="qss-form-item layui-form-item switch-line">
                            <div class="layui-form-label">是否存在代谢紊乱/心血管疾病等</div>
                            <div class="layui-input-inline qss-input-swipch">
                                <div class="switch3-2" data-qid="125" id="switch-125" title="是|否" option="0|1|2" value=""></div>
                            </div>
                            <div class="qss-form-item-checkbox layui-form-item" id="opn-125" style="display:none">
                                <input type="checkbox" lay-skin="primary" title="高血压" name="126" class="cv-12601" value="12601" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="糖尿病前期" name="126" class="cv-12602" value="12602" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="糖尿病" name="126" class="cv-12603" value="12603" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="低钾血症" name="126" class="cv-12604" value="12604" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="骨质疏松" name="126" class="cv-12605" value="12605" lay-filter="check1">
                                <!--                           <input type="checkbox" lay-skin="primary"  title="瘀斑"  name="126" class="cv-12606" value="12606" lay-filter="check1">-->
                                <input type="checkbox" lay-skin="primary" title="高脂血症" name="126" class="cv-12607" value="12607" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="心力衰竭" name="126" class="cv-12608" value="12608" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="冠心病" name="126" class="cv-12609" value="12609" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="睡眠呼吸暂停综合症" name="126" class="cv-12610" value="12610" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="精神障碍(抑郁症或焦虑症)" name="126" class="cv-12611" value="12611" lay-filter="check1">
                                <!--v1.1 移除-->
                                <!--                            <input type="checkbox" lay-skin="primary"  title="肿瘤史"  name="126" class="cv-12612" value="12612" lay-filter="check1">-->
                                <!--v1.1-->
                                <input type="checkbox" lay-skin="primary" title="超重/肥胖" name="126" class="cv-12613" value="12613" lay-filter="check1">
                            </div>
                        </div>
                        <div class="qss-form-item layui-form-item" id="zl-12612" style="display: none">
                            <div class="layui-form-label">恶性肿瘤原发部位：（可多选）</div>
                            <div class="qss-form-item-checkbox layui-form-item" id="opn-127">
                                <input type="checkbox" lay-skin="primary" title="肝脏" name="127" class="cv-12701" value="12701" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="胰腺" name="127" class="cv-12702" value="12702" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="胃" name="127" class="cv-12703" value="12703" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="结直肠" name="127" class="cv-12704" value="12704" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="乳腺" name="127" class="cv-12705" value="12705" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="宫颈" name="127" class="cv-12706" value="12706" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="卵巢" name="127" class="cv-12707" value="12707" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="子宫内膜" name="127" class="cv-12708" value="12708" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="前列腺" name="127" class="cv-12709" value="12709" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="膀胱" name="127" class="cv-12710" value="12710" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="肾脏" name="127" class="cv-12711" value="12711" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="淋巴瘤" name="127" class="cv-12712" value="12712" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="白血病" name="127" class="cv-12713" value="12713" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="肺部" name="127" class="cv-12714" value="12714" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="甲状腺" name="127" class="cv-12715" value="12715" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="其他" name="127" class="cv-12716" value="12716" lay-filter="check2">
                                <input type="text" class="layui-input checkbox-check-input cv-12716001" lay-verify="other_text" lay-verType="tips" id="12716-val" autocomplete="off" disabled="disabled">
                            </div>
                        </div>
                        <div class="qss-item-btn">
                            <a href="javascript:;">
                                <button type="button" lay-submit="" lay-filter="submit-btn" data-type="1">提交并跳转下一页</button>
                            </a>
                            <a href="javascript:;">
                                <button type="button" lay-submit="" lay-filter="submit-btn" data-type="0">保存并留在本页</button>
                            </a>
                            <a href="./qss2.html">
                                <button type="button">放弃编辑并跳转下一页</button>
                            </a>
                        </div>
                    </div>
                </form>
                <div class="fixed-nav">
                    <ul>
                        <li class="fixed-nav-curr"><a><span>个人疾病史</span><span class="complete_qss1"></span><div class="clear"></div></a></li>
                        <li><a href="./qss2.html"><span>垂体疾病评估</span><span class="complete_qss2"></span><div class="clear"></div></a></li>
                        <li><a href="./qss3.html"><span>垂体疾病用药</span><span class="complete_qss3"></span><div class="clear"></div></a></li>
                        <li><a href="./qss4.html"><span>合并症评估</span><span class="complete_qss4"></span><div class="clear"></div></a></li>
                        <li><a href="./qss5.html"><span>合并症用药</span><span class="complete_qss5"></span><div class="clear"></div></a></li>
                        <li><a href="./qss6.html"><span>垂体疾病治疗</span><span class="complete_qss6"></span><div class="clear"></div></a></li>
                    </ul>
                    <button class="submit-btn" lay-submit="" lay-filter="submit-btn" data-type="1">提交</button>
                </div>
            </div>
        </div>
    </div>
</body>
<script>
    //有关问题的数据
    var question = {
        111: [11102, '否', 's1'], //肾上腺皮质功能减退 1-a
        112: [11202, '否', 's1'], //甲状腺功能减退 1-b
        113: [11302, '否', 's1'], //性腺功能减退 1-c
        114: [11402, '否', 's1'], //生长激素缺乏 1-d
        115: [11502, '否', 's1'], //诊断时存在垂体后叶功能减退 2
        116: [11601, ''], //发现或诊断换有垂体疾病时间  3-a
        117: [0, '', 's1'], //首诊科室
        118: [11802, '否', 's1'], //是否体检或以外发现
        //是否存在肿瘤压迫临床症状 4-2
        119: [11902, '否', 's1'],
        //是否存在激素分泌亢进表现 4-3
        121: [12102, '否', 's1'],
        //是否存在垂体功能地下表现 4-4
        123: [12302, '否', 's1'],
        //是否存在代谢紊乱
        125: [12502, '否', 's1'],
        128: [12801, ''],
        //复选的内容
        'check_list': {}
    };

    function initForm(patient_id, callback) {
        //获取答案,初始化表单
        ajax_get(configUrl.qssInfo, {
            user_id: patient_id,
            visit_level: 1,
            template_id: 11
        }, (res) => {
            console.log(res);
            console.log(555);
            if (res.status != 0) {
                layer.msg(res.msg);
                return false;
            }
            var arr1 = [111, 112, 113, 114, 115, 118]; //单开关
            var arr2 = [119, 121, 123, 125]; //开关带选项
            var arr3 = [120, 122, 124, 126, 127]; //复选
            console.log(res.data.question_data);
            console.log(777);
            $.each(res.data.question_data, function(index, item) {
                qid = parseInt(item.question_id);

            console.log(qid);
                //开关
                if (arr1.includes(qid) || arr2.includes(qid)) {
                    if (item.answer.length > 0) {
                        if (item.answer[0].answer_id == (qid + '01')) { //选中
                            $("input[name='q" + qid + "']").attr('checked', true);
                            $("#switch-" + qid).attr('value', 1);
                            if (arr2.includes(qid)) { //带选项的开关，展开选项
                                $("#opn-" + qid).show();
                            }
                        } else {
                            $("input[name='q" + qid + "']").attr('checked', false);
                            $("#switch-" + qid).attr('value', 2);
                        }
                        question[qid][0] = item.answer[0].answer_id;
                        question[qid][1] = item.answer[0].answer_value;
                    } else {
                        question[qid][0] = 0;
                    }
                }

                //日期
                if (qid == 116) {
                    if (item.answer.length > 0) {
                        $("#faxian-date").val(item.answer[0].answer_value);
                        question[116][1] = item.answer[0].answer_value;
                    }

                }
                if (qid == 117) {
                    if (item.answer.length > 0) {
                        $(".cv-" + item.answer[0].answer_id).attr('checked', true);
                        question[117][0] = item.answer[0].answer_id;
                        question[117][1] = item.answer[0].answer_value;
                    }
                }
                //复选
                if (arr3.includes(qid)) { //带选项的开关，展开选项
                    //console.log(item.answer);
                    $.each(item.answer, function(index, item2) {
                        $(".cv-" + item2.answer_id).attr('checked', true);
                        if (item2.answer_id == 12716) {
                            $("#12716-val").val(item2.answer_value);
                        }
                        if (item2.answer_id == 12612) {
                            $('#zl-12612').show();
                        }
                        question['check_list'][item2.answer_id] = item2.answer_value;
                        if (item2.answer_id == 12007) {
                            $('.cv-12007001').prop('disabled', false)
                        }
                        if (item2.answer_id == 12007001) {
                            $('.cv-12007001').val(item2.answer_value);
                        }
                    });

                }
                //单选
            });

            callback();
        })
    }

    $(document).ready(function() {
        var height = $(window).height() - 2;
        //$('.container').height(height);
        var patient_id = getLocalStorage('patient_id');
        //console.log(patient_id);
        //完整度
        getCompletion();



        $('.duoxuan-btn button').click(function() {
            var val = $(this).attr('data-val');
            //console.log(val)
            if (val == 1) {
                $('#last-duoxuan').show();
            } else {
                $('#last-duoxuan').hide();
            }
        });

        layui.config({
            base: '../../../layui/layui_exts/'
        }).extend({
            switch3: 'switch3/switch3'
        }).use(['element', 'form', 'layer', 'laydate', 'laypage', 'switch3'], function() {
            var element = layui.element;
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var laypage = layui.laypage;
            var switch3 = layui.switch3;

            //时间最大时
            var now = new Date();
            var year = parseInt(now.getFullYear());
            var month = parseInt(now.getMonth() + 1);
            var day = now.getDate();
            var max_date = year + '-' + month + '-' + day;
            initForm(patient_id, function() {
                switch3.render({
                    elem: '.switch3',
                    done: function(val, item) {
                        qid = item.parent().parent().attr('data-qid');
                        //console.log('s-',val + '; qid='+ qid);
                        if (val == 0) {
                            question[qid][0] = 0;
                            question[qid][1] = '';
                        } else if (val == 1) {
                            question[qid][0] = qid + '01';
                            question[qid][1] = item.html();
                        } else if (val == 2) {
                            question[qid][0] = qid + '02';
                            question[qid][1] = item.html();
                        }
                    }
                });
                //带切换开头
                switch3.render({
                    elem: '.switch3-2',
                    done: function(val, item) {
                        qid = item.parent().parent().attr('data-qid');
                        var qidArr = ['119', '121', '123', '125'];
                        if (val == 0) {
                            $("#opn-" + qid).hide();
                            question[qid][0] = 0;
                            question[qid][1] = '';
                            if (qidArr.includes(qid)) {
                                var idStr = '#opn-' + qid;
                                $(idStr).children('input').each(function() {
                                    $(this).prop('checked', false);
                                    delete question.check_list[$(this).val()]
                                })
                                if (qid == 125) {
                                    $('#zl-12612').hide()
                                    $('#opn-127 input[name=127]').each(function(index, item) {
                                        $(item).prop('checked', false);
                                        delete question.check_list[$(item).val()]
                                    })
                                    $('.cv-12716001').val('');
                                    $('.cv-12716001').prop('disabled', true);
                                }
                                if (qid == 119) {
                                    $('.cv-12007001').val('');
                                    $('.cv-12007001').prop('disabled', true);
                                }
                            }
                        } else if (val == 1) {
                            question[qid][0] = qid + '01';
                            question[qid][1] = item.html();
                            $("#opn-" + qid).show();
                        } else if (val == 2) {
                            question[qid][0] = qid + '02';
                            question[qid][1] = item.html();
                            $("#opn-" + qid).hide();
                            if (qidArr.includes(qid)) {
                                var idStr = '#opn-' + qid;
                                $(idStr).children('input').each(function() {
                                    $(this).prop('checked', false);
                                    delete question.check_list[$(this).val()]
                                })
                                if (qid == 125) {
                                    $('#zl-12612').hide()
                                    $('#opn-127 input[name=127]').each(function(index, item) {
                                        $(item).prop('checked', false);
                                        delete question.check_list[$(item).val()]
                                    })
                                    $('.cv-12716001').val('');
                                    $('.cv-12716001').prop('disabled', true);
                                }
                                if (qid == 119) {
                                    $('.cv-12007001').val('');
                                    $('.cv-12007001').prop('disabled', true);
                                }
                            }
                        }
                        form.render();
                    }
                });
                form.render();
            });


            //发现时间
            laydate.render({
                elem: '#faxian-date',
                type: 'month',
                'max': max_date,
                // showBottom: false,

                change: function(value, date, endDate) {
                    if ($(".layui-laydate").length) {
                        $("#faxian-date").val(value);
                        $(".layui-laydate").remove();
                    }
                },
                done: function(value, date, endDate) {
                    question[116][1] = value;
                    question[116][0] = 11601;
                }

            });

            //第一类只有是否的切换
            form.on('switch(switch1)', function(data) {
                var qid = $(this).attr('data-qid');
                if (this.checked) {

                    question[qid][0] = qid + '01';
                    question[qid][1] = '是';
                } else {
                    question[qid][0] = qid + '02';
                    question[qid][1] = '否';
                }
                //console.log(question);
            })

            //3-b首诊科室切换
            form.on('radio(radio117)', function(data) {
                if (data.elem.checked == true) {
                    question[117][0] = data.value;
                    question[117][1] = $(this).attr('title');
                } else {
                    question[117][0] = 0;
                    question[117][1] = '';
                }

            });
            //第二类切换，带选项列表
            form.on('switch(switch2)', function(data) {
                var qid = $(this).attr('data-qid');
                if (this.checked) {
                    $("#opn-" + qid).show();
                    question[qid][0] = qid + '01';
                    question[qid][1] = '是';
                } else {
                    $("#opn-" + qid).hide();
                    question[qid][0] = qid + '02';
                    question[qid][1] = '否';
                }
                //console.log(question);
            })

            //复选选中与否切换
            form.on('checkbox(check1)', function(data) {
                var val = $(this).attr('title');
                var qid2 = data.value;

                if (this.checked) {
                    question['check_list'][qid2] = val;
                    if (qid2 == 12612) {
                        $('#zl-12612').show()
                    }
                    if (qid2 == 12007) {
                        $('.cv-12007001').prop('disabled', false);
                    }
                } else {
                    if (qid2 == 12612) {
                        $('#zl-12612').hide()
                        $('#opn-127 input[name=127]').each(function(index, item) {
                            $(item).prop('checked', false);
                            delete question.check_list[$(item).val()]
                        })
                        $('.cv-12716001').val('');
                        $('.cv-12716001').prop('disabled', true);
                    }
                    if (qid2 == 12007) {
                        $('.cv-12007001').val('');
                        $('.cv-12007001').prop('disabled', true);
                    }
                    delete question.check_list[qid2];
                    form.render();
                }

            });
            //最后一个多选 ，其它
            var checked12716 = 0;
            form.on('checkbox(check2)', function(data) {
                var qid2 = '12716';
                if (this.checked) {
                    question['check_list'][qid2] = $("#12716-val").val();
                    $('.cv-12716001').prop('disabled', false);
                    checked12716 = 1;
                } else {
                    checked12716 = 0;
                    $('.cv-12716001').val('');
                    $('.cv-12716001').prop('disabled', true);
                    delete question.check_list[qid2];
                }
                //console.log(question.check_list);
            });
            $("#12716-val").change(function() {
                if (checked12716 == 1) {
                    question['check_list']['12716'] = $(this).val();
                }

            });

            // v1.1 信息校验
            form.verify({
                other_text: function(value) {
                    if (value.length > 20) {
                        return '输入内容不能超过20个字';
                    }
                },
                date_116: function(value) {
                    if (value.length == 0) {
                        return '请输入诊断时间';
                    }
                },
            });

            form.on('submit(submit-btn)', function(data) {
                var jumpType = $(this).attr('data-type');
                var chapterId = 1101;
                var visitLevel = 1;
                var params = {
                    'hosp_id': getLocalStorage('hosp_id'),
                    'dept_id': getLocalStorage('dept_id'),
                    'user_id': getLocalStorage('patient_id'),
                    'doc_id': getLocalStorage('doc_id'),
                    'visit_level': 1,
                    'template_id': 11,
                    'terminal_flg': 0,
                    'data': [{
                        'visit_level': 1,
                        'user_id': getLocalStorage('patient_id'),
                        'doc_id': getLocalStorage('doc_id'),
                        "terminal_flg": "0",
                        'template_id': 11,
                        "datasource": "2",
                        'answer': []
                    }]
                };
                var answer = [];
                //第一类，只有是否的切换便利
                $.each(question, function(qid, item) {
                    if (item[2] == 's1') {
                        if (question[qid][0] != 0) {
                            answer.unshift({
                                'chapter_id': chapterId,
                                'question_id': qid,
                                'subquestion_id': qid,
                                'answer_id': question[qid][0],
                                'answer_name': question[qid][1],
                                'visit_level': visitLevel
                            });
                        }
                    }
                });
                //console.log(question.check_list);
                //第二类多选
                $.each(question.check_list, function(qid2, item) {
                        qid = parseInt(parseInt(qid2) / 100);
                        //console.log('checkbox',item);
                        answer.push({
                            'chapter_id': chapterId,
                            'question_id': qid,
                            'subquestion_id': qid,
                            'answer_id': qid2,
                            'answer_name': item,
                            'visit_level': visitLevel
                        });
                    })
                    //时间
                var newdate = $('#faxian-date').val();
                answer.push({
                    'chapter_id': chapterId,
                    'question_id': 116,
                    'subquestion_id': 116,
                    'answer_id': question[116][0],
                    'answer_name': newdate,
                    'visit_level': visitLevel
                });
                var cv12007001 = $('.cv-12007001').val();
                //console.log(cv12007001 != '')

                //console.log('aa');return false;
                answer.push({
                    'chapter_id': chapterId,
                    'question_id': 120,
                    'subquestion_id': 12007001,
                    'answer_id': 12007001,
                    'answer_name': cv12007001,
                    'visit_level': visitLevel
                });
                params.data[0].answer = answer;

                ajax_post(configUrl.qssInfo, params, function(res) {
                    console.log(res);
                    if (res.status == '0') {
                        layer.msg('操作成功', {
                            icon: 6,
                            time: 1000
                        }, function() {
                            if (jumpType == 0) {
                                //不跳转
                                window.location.reload();
                            } else {
                                //跳转
                                window.location.href = './qss2.html';
                            }
                        });
                    } else {
                        layer.msg(res.msg, {
                            icon: 5
                        });
                    }
                })
            });

        })
    })
</script>

</html>
